#include "StdAfx.h"
#include "Settings.h"
#include "ConfigFile.h"
#include "input.h"

char path_config[1024];		//path to configuration file (set by main())
config_t config;			   //configuration
config_t defaults;         //config defaults


static configvar_t configvars[] = {
	{&config.path_rom,		CFG_STR,	"ROM Path",					"Current path to ROM images"},
	{&config.path_state,		CFG_STR,	"State Path",				"Path to state saves"},
	{&config.path_cheat,		CFG_STR,	"Cheat Path",				"Path to cheat data files"},
	{&config.path_shots,		CFG_STR,	"Screenshot Path",		"Path to screenshots"},
	{&config.fullscreen,		CFG_U32,	"Fullscreen",				"Fullscreen video mode (0=320x240,1=640x480,2=800x600,3=1024x768,4=1280x1024)"},
	{&config.windowed,		CFG_U32,	"Windowed",					"Windowed mode flag (1=windowed,0=fullscreen)"},
	{&config.windowscale,	CFG_U32,	"Window Scale",			"Windowed mode scale (1, 2, 3, or 4)"},
	{&config.filter,			CFG_U32,	"Filter",					"Video Filter"},
	{&config.showinfo,		CFG_U32,	"Show Info",				"Show ROM Name and FPS at top of screen during gameplay"},
	{&config.soundenabled,	CFG_U32,	"Sound Enabled",			"Sound enabled"},
	{&config.soundchannels,	CFG_U32,	"Sound Channels",			"NES Sound channels enabled (bit mask)"},
	{&config.shotformat,		CFG_U32,	"Screenshot Format",		"Screenshot Image Format (0=pcx,1=png)"},
	{&config.gui_keys[0],	CFG_U32,	"GUI Key Menu",			"GUI Key - Menu"},
	{&config.gui_keys[1],	CFG_U32,	"GUI Key Load State",	"GUI Key - Load State"},
	{&config.gui_keys[2],	CFG_U32,	"GUI Key Save State",	"GUI Key - Save State"},
	{&config.gui_keys[3],	CFG_U32,	"GUI Key Disk Flip",		"GUI Key - Disk Flip"},
	{&config.gui_keys[4],	CFG_U32,	"GUI Key Screenshot",	"GUI Key - Screenshot"},
	{&config.gui_keys[5],	CFG_U32,	"GUI Key Fast Forward",	"GUI Key - Fast Forward"},
	{&config.joy_keys[0][0],CFG_U32,	"Joypad 1 Key A",			"Joypad 1 Key - Button A"},
	{&config.joy_keys[0][1],CFG_U32,	"Joypad 1 Key B",			"Joypad 1 Key - Button B"},
	{&config.joy_keys[0][2],CFG_U32,	"Joypad 1 Key Select",	"Joypad 1 Key - Button Select"},
	{&config.joy_keys[0][3],CFG_U32,	"Joypad 1 Key Start",	"Joypad 1 Key - Button Start"},
	{&config.joy_keys[0][4],CFG_U32,	"Joypad 1 Key Up",		"Joypad 1 Key - Button Up"},
	{&config.joy_keys[0][5],CFG_U32,	"Joypad 1 Key Down",		"Joypad 1 Key - Button Down"},
	{&config.joy_keys[0][6],CFG_U32,	"Joypad 1 Key Left",		"Joypad 1 Key - Button Left"},
	{&config.joy_keys[0][7],CFG_U32,	"Joypad 1 Key Right",	"Joypad 1 Key - Button Right"},
	{&config.joy_keys[1][0],CFG_U32,	"Joypad 2 Key A",			"Joypad 2 Key - Button A"},
	{&config.joy_keys[1][1],CFG_U32,	"Joypad 2 Key B",			"Joypad 2 Key - Button B"},
	{&config.joy_keys[1][2],CFG_U32,	"Joypad 2 Key Select",	"Joypad 2 Key - Button Select"},
	{&config.joy_keys[1][3],CFG_U32,	"Joypad 2 Key Start",	"Joypad 2 Key - Button Start"},
	{&config.joy_keys[1][4],CFG_U32,	"Joypad 2 Key Up",		"Joypad 2 Key - Button Up"},
	{&config.joy_keys[1][5],CFG_U32,	"Joypad 2 Key Down",		"Joypad 2 Key - Button Down"},
	{&config.joy_keys[1][6],CFG_U32,	"Joypad 2 Key Left",		"Joypad 2 Key - Button Left"},
	{&config.joy_keys[1][7],CFG_U32,	"Joypad 2 Key Right",	"Joypad 2 Key - Button Right"},
	{&config.joy_keys[2][0],CFG_U32,	"Joypad 3 Key A",			"Joypad 3 Key - Button A"},
	{&config.joy_keys[2][1],CFG_U32,	"Joypad 3 Key B",			"Joypad 3 Key - Button B"},
	{&config.joy_keys[2][2],CFG_U32,	"Joypad 3 Key Select",	"Joypad 3 Key - Button Select"},
	{&config.joy_keys[2][3],CFG_U32,	"Joypad 3 Key Start",	"Joypad 3 Key - Button Start"},
	{&config.joy_keys[2][4],CFG_U32,	"Joypad 3 Key Up",		"Joypad 3 Key - Button Up"},
	{&config.joy_keys[2][5],CFG_U32,	"Joypad 3 Key Down",		"Joypad 3 Key - Button Down"},
	{&config.joy_keys[2][6],CFG_U32,	"Joypad 3 Key Left",		"Joypad 3 Key - Button Left"},
	{&config.joy_keys[2][7],CFG_U32,	"Joypad 3 Key Right",	"Joypad 3 Key - Button Right"},
	{&config.joy_keys[3][0],CFG_U32,	"Joypad 4 Key A",			"Joypad 4 Key - Button A"},
	{&config.joy_keys[3][1],CFG_U32,	"Joypad 4 Key B",			"Joypad 4 Key - Button B"},
	{&config.joy_keys[3][2],CFG_U32,	"Joypad 4 Key Select",	"Joypad 4 Key - Button Select"},
	{&config.joy_keys[3][3],CFG_U32,	"Joypad 4 Key Start",	"Joypad 4 Key - Button Start"},
	{&config.joy_keys[3][4],CFG_U32,	"Joypad 4 Key Up",		"Joypad 4 Key - Button Up"},
	{&config.joy_keys[3][5],CFG_U32,	"Joypad 4 Key Down",		"Joypad 4 Key - Button Down"},
	{&config.joy_keys[3][6],CFG_U32,	"Joypad 4 Key Left",		"Joypad 4 Key - Button Left"},
	{&config.joy_keys[3][7],CFG_U32,	"Joypad 4 Key Right",	"Joypad 4 Key - Button Right"},
	{&config.recent[0],CFG_STR,		"Recent File 0",			"Recent File 0"},
	{&config.recent[1],CFG_STR,		"Recent File 1",			"Recent File 1"},
	{&config.recent[2],CFG_STR,		"Recent File 2",			"Recent File 2"},
	{&config.recent[3],CFG_STR,		"Recent File 3",			"Recent File 3"},
	{&config.recent[4],CFG_STR,		"Recent File 4",			"Recent File 4"},
	{&config.recent[5],CFG_STR,		"Recent File 5",			"Recent File 5"},
	{&config.recent[6],CFG_STR,		"Recent File 6",			"Recent File 6"},
	{&config.recent[7],CFG_STR,		"Recent File 7",			"Recent File 7"},
	{&config.recent[8],CFG_STR,		"Recent File 8",			"Recent File 8"},
	{&config.recent[9],CFG_STR,		"Recent File 9",			"Recent File 9"},
	{0,0,0,0}
};

#define COPYKEY(k1,k2)						\
	{												\
	k1.internalcode = k2.internalcode;	\
	k1.scancode = k2.scancode;				\
	}

extern char settings_subkey[];
static char romdir_default[512] = "c:\\breem\\rom";
static char statedir_default[512] = "c:\\breem\\state";
static char hidir_default[512] = "c:\\breem\\highscore";
static char nvramdir_default[512] = "c:\\breem\\nvram";
static keyconfig_t defaultkeys[MAX_KEYS] =		//default keys
	{
	{I_UP,		SDLK_UP},
	{I_DOWN,		SDLK_DOWN},
	{I_LEFT,		SDLK_LEFT},
	{I_RIGHT,	SDLK_RIGHT},
	{I_B1,		SDLK_z},
	{I_B2,		SDLK_x},
	{I_B3,		SDLK_c},
	{I_B4,		SDLK_a},
	{I_B5,		SDLK_s},
	{I_B6,		SDLK_d},
	{I2_UP,		SDLK_i},
	{I2_DOWN,	SDLK_k},
	{I2_LEFT,	SDLK_j},
	{I2_RIGHT,	SDLK_l},
	{I2_B1,		SDLK_r},
	{I2_B2,		SDLK_t},
	{I2_B3,		SDLK_y},
	{I2_B4,		SDLK_f},
	{I2_B5,		SDLK_g},
	{I2_B6,		SDLK_h},
	{I_COIN1,	SDLK_5},
	{I_COIN2,	SDLK_6},
	{I_COIN3,	SDLK_7},
	{I_TILT,	SDLK_0},
	{I_START1,	SDLK_1},
	{I_START2,	SDLK_2},
	{I_START3,	SDLK_3},
	{I_START4,	SDLK_4},
	{I_SERVICE,	SDLK_7},
	{I_ADVANCE,	SDLK_0},
	{I_AUTOUP,	SDLK_9},
	{I_HRESET,	SDLK_8},
	};

CSettings::CSettings()
{
char curdir[512] = "./";
int i;

//GetCurrentDirectory(512,curdir);
sprintf(romdir_default,"%s/rom",curdir);
sprintf(statedir_default,"%s/state",curdir);
sprintf(hidir_default,"%s/highscore",curdir);
sprintf(nvramdir_default,"%s/nvram",curdir);
for(i=0;i<16;i++)
	dip_default[i] = 0;
for(i=0;i<MAX_KEYS;i++)
	COPYKEY(keyconfig[i],defaultkeys[i]);
SetDefault();
Load();
}

CSettings::~CSettings()
{
Save();
}

void CSettings::SetDefault()
{
int i;

strcpy(romdir,romdir_default);
strcpy(statedir,statedir_default);
strcpy(hidir,hidir_default);
strcpy(nvramdir,nvramdir_default);
for(i=0;i<16;i++)
	dip[i] = dip_default[i];
for(i=0;i<MAX_KEYS;i++)
	COPYKEY(keyconfig[i],defaultkeys[i]);
lockfps = 1;
startupstate = 0;
}

int CSettings::Load()
{
return(0);
}

int CSettings::Save()
{
return(0);
}
